using System;
using UnityEngine;

namespace IQIGame.Onigao.Framework.Serialization
{
    public class Int3 : ISerializeByteBuf
    {
        public int x;
        public int y;
        public int z;

        public Int3()
        {
        }

        public Int3(int x, int y, int z)
        {
            this.x = x;
            this.y = y;
            this.z = z;
        }

        public Int3(Vector3Int rV3Int)
        {
            this.x = rV3Int.x;
            this.y = rV3Int.y;
            this.z = rV3Int.z;
        }

        public static implicit operator Vector3Int(Int3 int3)
        {
            var v3 = new Vector3Int();
            v3.x = int3.x;
            v3.y = int3.y;
            v3.z = int3.z;
            return v3;
        }

        public static implicit operator Int3(Vector3Int v3)
        {
            return new Int3(v3);
        }

        public Int3(UnityEngine.Vector3Int rV3Int)
        {
            this.x = rV3Int.x;
            this.y = rV3Int.y;
            this.z = rV3Int.z;
        }

        public static implicit operator UnityEngine.Vector3Int(Int3 int3)
        {
            var v3 = new UnityEngine.Vector3Int();
            v3.x = int3.x;
            v3.y = int3.y;
            v3.z = int3.z;
            return v3;
        }

        public static implicit operator Int3(UnityEngine.Vector3Int v3)
        {
            return new Int3(v3);
        }

        public Int3(Vector3 rV3Int)
        {
            this.x = (int)Math.Round(rV3Int.x);
            this.y = (int)Math.Round(rV3Int.y);
            this.z = (int)Math.Round(rV3Int.z);
        }

        public static implicit operator Vector3(Int3 int3)
        {
            var v3 = new Vector3();
            v3.x = int3.x;
            v3.y = int3.y;
            v3.z = int3.z;
            return v3;
        }

        public static implicit operator Int3(Vector3 v3)
        {
            return new Int3(v3);
        }

        public void Serialize(ByteBuf _buf)
        {
            _buf.WriteInt(this.x);
            _buf.WriteInt(this.y);
            _buf.WriteInt(this.z);
        }

        public void DeSerialize(ByteBuf _buf)
        {
            this.x = _buf.ReadInt();
            this.y = _buf.ReadInt();
            this.z = _buf.ReadInt();
        }
    }
}
